﻿/*
------------------------------------------------------------------------------
This source file is a part of Flexible Localization.

Copyright (c) 2011 - 2013 Florian Haag

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
------------------------------------------------------------------------------
 */
using System;

using Gtk;

using TwoLayeredGUI.Samples.SampleCore;
using TwoLayeredGUI.Gtk;

namespace TwoLayeredGUI.Samples.SampleGtkSharpFrontend
{
	/// <summary>
	/// The main window of the application.
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow() : base("SampleGtkSharpFrontend")
		{
			Button btn;
			
			SetDefaultSize(434, 340);
			
			var nb = new Notebook();
			this.Add(nb);
			
			// message box
			nb.AppendPageWithTitle(CreateButtonPanel(new ExampleButton("Simple Message Box", bSimpleMessageBoxClick),
			                                         new ExampleButton("Question", bQuestionClick),
			                                         new ExampleButton("Exception", bExceptionClick),
			                                         new ExampleButton("Exception as a Warning", bExceptionAsWarningClick),
			                                         new ExampleButton("With many Buttons", bWithManyButtonsClick),
			                                         new ExampleButton("Long message text", bLongMessageClick),
			                                         new ExampleButton("Buttons on the side", bQuestionWithButtonsOnSideClick)),
			                       "MessageBox");
			
			// input box
			nb.AppendPageWithTitle(CreateButtonPanel(new ExampleButton("Simple Input Box", bSimpleInputBoxClick),
			                                         new ExampleButton("Several Fields", bSeveralFieldsInputBoxClick),
			                                         new ExampleButton("Various Value Types", bVariousTypesInputBoxClick),
			                                         new ExampleButton("Validated Values", bValidatedValuesInputBoxClick),
			                                         new ExampleButton("Multiple Fonts", bMultiFontInputBoxClick),
			                                         new ExampleButton("Unique Values", bUniqueValuesInputBoxClick),
			                                         new ExampleButton("Edit Commands", bEditCommandsInputBoxClick)),
			                       "InputBox");
			
			// progress dialog
			nb.AppendPageWithTitle(CreateButtonPanel(new ExampleButton("Without Details", bWithoutDetailsProgressClick),
			                                         new ExampleButton("With Details", bWithDetailsProgressClick),
			                                         new ExampleButton("Non-modally", bNonModalProgressClick),
			                                         new ExampleButton("With Button", bWithButtonProgressClick)),
			                       "ProgressDialog");
			
			// flow view
			{
				Frame frame;
				
				nb.AppendPageWithTitle(pFlowView, "FlowView");
				
				rbFlowHorizontally = new RadioButton("Flow horizontally");
				pFlowView.AttachInCell(rbFlowHorizontally, 0, 0, GtkUtilities.AllAttachOptions, AttachOptions.Shrink | AttachOptions.Fill, 3);
				rbFlowHorizontally.Toggled += RbFlowHVToggled;
				
				rbFlowVertically = new RadioButton(rbFlowHorizontally, "Flow vertically");
				pFlowView.AttachInCell(rbFlowVertically, 1, 0, GtkUtilities.AllAttachOptions, AttachOptions.Shrink | AttachOptions.Fill, 3);
				rbFlowVertically.Toggled += RbFlowHVToggled;
				
				flowEventArea.Add(flowArea);
				
				frame = new Frame("Alignment");
				flowSettingsPane.Add(frame);
				
				SetFlowLayoutPaned(new HPaned());
				
				var alignmentPadding = new Alignment(0, 0, 1, 1) {
					LeftPadding = 3,
					TopPadding = 3,
					RightPadding = 3,
					BottomPadding = 3
				};
				frame.Add(alignmentPadding);
				
				VBox alignmentContents = new VBox(false, 2);
				alignmentPadding.Add(alignmentContents);
				
				rbStart = new RadioButton("Start");
				alignmentContents.PackStart(rbStart, false, true, 0);
				rbStart.Toggled += RbAlignmentChanged;
				
				rbCenter = new RadioButton(rbStart, "Center");
				alignmentContents.PackStart(rbCenter, false, true, 0);
				rbCenter.Toggled += RbAlignmentChanged;
				
				rbEnd = new RadioButton(rbStart, "End");
				alignmentContents.PackStart(rbEnd, false, true, 0);
				rbEnd.Toggled += RbAlignmentChanged;
				
				btn = new Button() {
					Label = "Regenerate Flow Items"
				};
				pFlowView.Attach(btn, 0, 2, 2, 3, AttachOptions.Fill | AttachOptions.Expand, AttachOptions.Fill | AttachOptions.Shrink, 3, 3);
				btn.Clicked += delegate(object sender, EventArgs e) {
					RefreshFlowItems();
				};
			}
			
			// wizard
			nb.AppendPageWithTitle(CreateButtonPanel(new ExampleButton("Hello World", bHellWorldWzClick),
			                                         new ExampleButton("Person", bPersonWzClick),
			                                         new ExampleButton("Person List", bPersonListWzClick),
			                                         new ExampleButton("Progress Page", bProgressPageWzClick)),
			                       "Wizard");
			
			// file system
			nb.AppendPageWithTitle(CreateButtonPanel(new ExampleButton("Open File Dialog", bOpenFileDialogClick),
			                                         new ExampleButton("Save File Dialog", bSaveFileDialogClick),
			                                         new ExampleButton("Open Files Dialog", bOpenFilesDialogClick),
			                                         new ExampleButton("Save Files Dialog", bSaveFilesDialogClick),
			                                         new ExampleButton("Select Directory Dialog", bSelectDirectoryClick)),
			                       "File System");
			
			InitializeFlowView();
		}
		
		// message box
		
		private void bSimpleMessageBoxClick()
		{
			MessageBox.Show(Example.GetHelloWorldMessage());
		}
		
		private void bQuestionClick()
		{
			MessageBox.Show(Example.GetConfirmationMessage());
		}
		
		private void bExceptionClick()
		{
			MessageBox.Show(Example.GetExceptionMessage());
		}
		
		private void bExceptionAsWarningClick()
		{
			MessageBox.Show(Example.GetExceptionWarning());
		}
		
		private void bWithManyButtonsClick()
		{
			MessageBox.Show(Example.GetMessageWithManyButtons());
		}
		
		private void bLongMessageClick()
		{
			MessageBox.Show(Example.GetLongMessage());
		}
		
		private void bQuestionWithButtonsOnSideClick()
		{
			MessageBox.Show(Example.GetConfirmationMessageWithButtonsOnSide());
		}
		
		// input box
		
		private void bSimpleInputBoxClick()
		{
			object[] results;
			InputBox.Show(Example.GetHelloWorldInput(), out results);
		}
		
		private void bSeveralFieldsInputBoxClick()
		{
			object[] results;
			InputBox.Show(Example.GetNameInput(), out results);
		}
		
		private void bVariousTypesInputBoxClick()
		{
			object[] results;
			InputBox.Show(Example.GetMultiTypeInput(), out results);
		}
		
		private void bValidatedValuesInputBoxClick()
		{
			object[] results;
			InputBox.Show(Example.GetValidatedInput(), out results);
		}
		
		private void bMultiFontInputBoxClick()
		{
			object[] results;
			InputBox.Show(Example.GetMultiFontInput(), out results);
		}
		
		private void bUniqueValuesInputBoxClick()
		{
			object[] results;
			InputBox.Show(Example.GetUniqueValuesInput(), out results);
		}
		
		private void bEditCommandsInputBoxClick()
		{
			object[] results;
			InputBox.Show(Example.GetEditCommandsInput(new GUIProvider()), out results);
		}
		
		// progress dialog
		
		private void bWithoutDetailsProgressClick()
		{
			var controller = ProgressDialog.Create(Example.GetProgressWithoutDetails());
			controller.ShowDialog<object>(Example.WorkWithProgress, null);
		}
		
		private void bWithDetailsProgressClick()
		{
			var controller = ProgressDialog.Create(Example.GetProgressWithDetails());
			controller.ShowDialog<object>(Example.WorkWithProgress, null);
		}
		
		private void bNonModalProgressClick()
		{
			var controller = ProgressDialog.Create(Example.GetProgressWithDetails());
			controller.Show<object>(Example.WorkWithProgress, null);
		}
		
		private void bWithButtonProgressClick()
		{
			var controller = ProgressDialog.Create(Example.GetProgressWithButton());
			controller.ProgressDialogClosed += (s, ea) => {
				TwoLayeredGUI.Gtk.MessageBox.Show("The operation was " + (ea.Completed ? "completed" : "canceled") + ".");
			};
			controller.ShowDialog<object>(Example.WorkWithProgress, null);
		}
	}
}
